
import Vue from 'vue'
// 各个js文件有各自的上下文，作用域和执行环境
Vue.directive("clickoutside", {
  bind: function(el, binding, vnode) {
      function documentHandler(e) {
          if (el.contains(e.target)) {
            return false;
          };
          if (binding.expression) {
            // 执行绑定的表达式
            binding.value(e);
          };
      };
      el._vueClickOutside_ = documentHandler;
      // ios 移动端内核 safari -webkit- document body无法监听click和touch tap事件
      // 事件ActionListener click touch/tap press keyup keypress
      document.getElementById('app').addEventListener("click", documentHandler);
      // document.body.addEventListener("touch", documentHandler);
  },
  unbind: function(el, binding) {
      // document.removeEventListener('click', el._vueClickOutside_);
      document.getElementById('app').removeEventListener("click", el._vueClickOutside_);
      // document.removeEventListener('touch', el._vueClickOutside_);
      delete el._vueClickOutside_;
  },
});
